package com.zyk.leetcode;

import java.util.Stack;

/**
 * @author zhangsan
 * @date 2021/4/7 16:47
 */
public class M0206 {

    // https://leetcode-cn.com/problems/palindrome-linked-list-lcci/
    public static boolean isPalindrome(ListNode head) {
        Stack<ListNode> nodeStack = new Stack<>();
        ListNode cur = head;
        while (cur != null) {
            nodeStack.push(cur);
            cur = cur.next;
        }
        cur = head;
        while (cur != null) {
            if( !(cur.val == nodeStack.pop().val) ) {
                return false;
            }
            cur = cur.next;
        }
        return true;

    }

}
